package com.main.login.interfaces.assembler;

import cn.dev33.satoken.stp.StpUtil;
import com.main.common.base.base.BaseAssembler;
import com.main.common.base.base.BaseAssemblerFactory;
import com.main.common.utils.ConfigUtil;
import com.main.common.utils.UUIDUtil;
import com.main.login.domain.user.aggregates.Account;
import com.main.login.interfaces.dto.AddAccountDTO;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import org.springframework.context.i18n.LocaleContextHolder;

import java.time.ZoneId;
import java.time.ZonedDateTime;

public class AddAccountAssembler {
    private final BaseAssembler<Account, AddAccountDTO> baseAssembler;
    public AddAccountAssembler(@NotNull BaseAssemblerFactory baseAssemblerFactory) {
        this.baseAssembler = baseAssemblerFactory.getService(AddAccountDTO.class);
    }
    private final String systemId =  ConfigUtil.getProperty("Default.SystemId");

    private final String sessionTimeZone = StpUtil.getSession().getString("sessionTimeZone");

    public Account toEntity(AddAccountDTO addAccountDTO) {
//        addAccountDTO.setCreatedAt(ZonedDateTime.now().withZoneSameInstant(ZoneId.of(sessionTimeZone)).toLocalDateTime());
//        addAccountDTO.setCreatedBy(systemId);
        Account account =new Account();
        account = baseAssembler.toEntity(addAccountDTO, account);
        account.setId(new UUIDUtil().getId());
        account.setNumber(addAccountDTO.getNumber());
        account.setPassword(addAccountDTO.getPassword());
        return account;
    }
}